package com.controller.cart;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import com.dto.GooglemapsDTO;
import com.dto.merchant.UserDTO;
import com.model.dao.GooglemapsTable;
import com.model.dao.UserTable;
import com.model.dao.UserTableDAO;

@ManagedBean(name = "loginController")
@SessionScoped
public class LoginController implements Serializable {

	private static final long serialVersionUID = -6288624083533132724L;

	public UserDTO retrieveUserDetails(String loginId) throws Exception {

		UserTableDAO dao = new UserTableDAO();
		UserTable table = dao.findByUserName(loginId);
		UserDTO dto = new UserDTO();
		dto.setArea(table.getArea());
		dto.setCity(table.getCity());
		dto.setEmail(table.getEmail());
		dto.setHouseno(table.getHouseno());
		dto.setLandmark(table.getLandmark());
		dto.setMobileno(table.getMobileno());
		dto.setName(table.getName());
		dto.setStreet(table.getStreet());
		dto.setIduserTable(table.getIduserTable());
		GooglemapsTable googlemapsTable = table.getGooglemapsTable();
		if (null != googlemapsTable) {
			dto.setGooglemapsDTO(new GooglemapsDTO(googlemapsTable.getLat(),
					googlemapsTable.getLang(), dto));
		}
		return dto;
	}

	public boolean validateLogin(String uid, String pwd) throws Exception {
		UserTableDAO dao = new UserTableDAO();
		UserTable table = dao.findByUserName(uid);
		boolean validateFlag = false;
		if (null!=table && null!=table.getPassword()&&pwd.equalsIgnoreCase(table.getPassword())) {
			validateFlag = true;
		}
		return validateFlag;
	}
	
	
}
